package com.hrbxlh.virtualization.dto;

import cn.hutool.core.util.NetUtil;
import com.hrbxlh.virtualization.enums.ContainerStatusEnum;
import com.hrbxlh.virtualization.pojo.Container;
import com.hrbxlh.virtualization.vo.ContainerVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.beans.BeanUtils;

/**
 * @author cheer
 */
public class ContainerDTO {

    private Long id;

    private String rancherId;

    private String dockerId;

    private String ip;

    private Integer containerStatus;

    private String stuorteaId;

    private String imageName;

    private String userName;

    private String className;

    private String courseName;

    public Container convertToContainer() {
        Container container = new Container();
        BeanUtils.copyProperties(this, container);
        container.setIp((int) NetUtil.ipv4ToLong(ip));
        return container;
    }

    public ContainerVO convertToContainerVO() {
        ContainerVO containerVO = new ContainerVO();
        BeanUtils.copyProperties(this, containerVO);
        containerVO.setName(rancherId);
        containerVO.setStatus(ContainerStatusEnum.codeToMessage(containerStatus));
        containerVO.setStuorteaName(userName);
        if (StringUtils.isBlank(className)) {
            containerVO.setClassName("-");
        }
        if (StringUtils.isBlank(courseName)) {
            containerVO.setCourseName("-");
        }
        return containerVO;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getRancherId() {
        return rancherId;
    }

    public void setRancherId(String rancherId) {
        this.rancherId = rancherId;
    }

    public String getDockerId() {
        return dockerId;
    }

    public void setDockerId(String dockerId) {
        this.dockerId = dockerId;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getContainerStatus() {
        return containerStatus;
    }

    public void setContainerStatus(Integer containerStatus) {
        this.containerStatus = containerStatus;
    }

    public String getStuorteaId() {
        return stuorteaId;
    }

    public void setStuorteaId(String stuorteaId) {
        this.stuorteaId = stuorteaId;
    }

    public String getImageName() {
        return imageName;
    }

    public void setImageName(String imageName) {
        this.imageName = imageName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("id", id)
                .append("rancherId", rancherId)
                .append("dockerId", dockerId)
                .append("ip", ip)
                .append("containerStatus", containerStatus)
                .append("stuorteaId", stuorteaId)
                .append("imageName", imageName)
                .append("userName", userName)
                .append("className", className)
                .append("courseName", courseName)
                .toString();
    }
}
